package com.qf.lja.service;

import com.qf.lja.dao.OrderDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(urlPatterns = "/createOrder")
public class CreateOrderService extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //utf-8
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String u_id = req.getParameter("u_id");
        String num = req.getParameter("sum");
        String a_id = req.getParameter("a_id");

        OrderDao orderDao = new OrderDao();
        String orderId = orderDao.createorder(a_id, u_id, num);

        req.setAttribute("order", orderDao.findOrderById(orderId));
        req.getRequestDispatcher("/orderSuccess.jsp").forward(req, resp);
    }
}
